//
//  YZAutoTitleCell.m
//  VET
//
//  Created by Lam BG on 2018/7/19.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZAutoTitleCell.h"

#import "YZAutoRowModel.h"

@interface YZAutoTitleCell ()

@property (weak, nonatomic) IBOutlet UILabel *infoLabel;

@property (weak, nonatomic) IBOutlet UITextView *textView;

@property (weak, nonatomic) UILabel *placeHolderLabel;

@end

@implementation YZAutoTitleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self setupTextView];
    
    @weakify(self);
    [[self.textView.rac_textSignal distinctUntilChanged] subscribeNext:^(NSString *content) {
        
        @strongify(self);
        self.rowModel.displayValue = self.rowModel.paramValue = content;
    }];
}

- (void)setupTextView {
    
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"点击输入任务内容...";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = [UIColor lightGrayColor];
    [placeHolderLabel sizeToFit];
    [self.textView addSubview:placeHolderLabel];
    self.placeHolderLabel = placeHolderLabel;
    
    // same font
    self.textView.font = [UIFont systemFontOfSize:14.f];
    placeHolderLabel.font = [UIFont systemFontOfSize:14.f];
    
    [self.textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
}

- (void)setupCellView {
    [super setupCellView];
    
    self.infoLabel.text = self.rowModel.title;
    self.textView.text = self.rowModel.displayValue;
    self.placeHolderLabel.text = self.rowModel.tips;
    
    // 查看详情
    if (self.rowModel.displayValue.length == 0 && self.rowModel.isUnEdit == YES) {
        
        // 没有输入数据显示 无
        self.placeHolderLabel.text = @"无";
    }
}

@end





